import {getStorage, setStorage} from 'hcg-storage';

const recommendList = getStorage('recommendList') || [];

export default {
	state: recommendList,
	mutations: {
		setRecommendList(state, recommendList) {
			state.splice(0);
			for (let item of recommendList) {
				state.push(item);
			}
			setStorage('recommendList', state);
		}
	},
	actions: {
		setRecommendList({commit}, recommendData) {
			commit('setRecommendList', recommendData);
		}
	},
	getters: {
		guessLikeList(state) {
			let arr = [];
			let indexArr = [];
			for (let i = 0; i < 4; i++) {
				let index = Math.floor(Math.random() * state.length);
				if (indexArr.indexOf(index) > -1) {
					i--;
					continue;
				}
				indexArr.push(index);
				arr.push(state[index]);
			}
			return arr;
		}
	}
}
